package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.PlaceMapper;
import com.haoan.index.domain.Place;
import com.haoan.index.service.PlaceService;

/**
 * 景区Service业务层处理
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Service
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper,Place> implements PlaceService
{
    /**
     * 查询景区
     *
     * @param id 景区主键
     * @return 景区
     */
    @Override
    public Place selectPlaceById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询景区列表
     *
     * @param place 景区
     * @return 景区
     */
    @Override
    public List<Place> selectPlaceList(Place place)
    {
        LambdaQueryWrapper<Place> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(place.getId() != null, Place::getId, place.getId());
        queryWrapper.like(place.getName() != null, Place::getName, place.getName());
        queryWrapper.eq(place.getPicture() != null, Place::getPicture, place.getPicture());
        queryWrapper.like(place.getRegion() != null, Place::getRegion, place.getRegion());
        queryWrapper.eq(place.getPrice() != null, Place::getPrice, place.getPrice());
        queryWrapper.eq(place.getGrade() != null, Place::getGrade, place.getGrade());
        queryWrapper.eq(place.getDetail() != null, Place::getDetail, place.getDetail());
        queryWrapper.eq(place.getCreateTime() != null, Place::getCreateTime, place.getCreateTime());
        queryWrapper.eq(place.getCreateBy() != null, Place::getCreateBy, place.getCreateBy());
        queryWrapper.eq(place.getUpdateTime() != null, Place::getUpdateTime, place.getUpdateTime());
        queryWrapper.eq(place.getUpdateBy() != null, Place::getUpdateBy, place.getUpdateBy());
        queryWrapper.eq(Place::getValiFlag,ValiFlag.VALID );
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增景区
     *
     * @param place 景区
     * @return 结果
     */
    @Transactional
    @Override
    public int insertPlace(Place place)
    {
        return baseMapper.insert(place);
    }

    /**
     * 修改景区
     *
     * @param place 景区
     * @return 结果
     */
    @Transactional
    @Override
    public int updatePlace(Place place)
    {
        return baseMapper.updateById(place);
    }

    /**
     * 批量删除景区
     *
     * @param ids 需要删除的景区主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePlaceByIds(Long [] ids)
    {
        Place place = new Place();
        place.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<Place> updQw = new LambdaQueryWrapper<>();
        updQw.in(Place::getId, ids);
        return baseMapper.update(place, updQw);
    }

    /**
     * 删除景区信息
     *
     * @param id 景区主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        Place place = getById(id);
        place.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(place);
    }
}
